package com.example.yubo.broadnotifytest_403yb;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    private EditText editText;
    private Button btnsend,btnnotify;
    private String UNIQUE_STRING="com.example.yubo.broadnotifytest_403yb";
    //定义这个  View.OnClickListener  直接setListener
  private View.OnClickListener listener= new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch(v.getId()){
                case R.id.button://发送广播
                    Intent intent=new Intent(UNIQUE_STRING);
                    intent.putExtra("para2",editText.getText().toString());
                    sendBroadcast(intent);
                    //定义一个子类 在mainfest里边
                    break;
                case R.id.button2://清楚消息
                MyReceiver.manager.cancel(MyReceiver.notifyID);
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init(){
        editText= (EditText) findViewById(R.id.editText);
        btnnotify= (Button) findViewById(R.id.button2);
        btnsend= (Button) findViewById(R.id.button);

        //直接在下边 set匿名对象
        //在类里边 Oncreat 方法
        //接口对象
        btnsend.setOnClickListener(listener);
        btnnotify.setOnClickListener(listener);

    }
}
